package it.polimi.travelDream.web.beans;


import it.polimi.it.TravelDream.ejb.UserMgr;
import it.polimi.it.TravelDream.ejb.eaos.ExcursionDTO;
import it.polimi.it.TravelDream.entities.BasicProdMgr;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class SearchExcursionBean {
	
	@EJB
	private BasicProdMgr basicProdMgr;
	
	@EJB
	private UserMgr userMgr;

//
	private List<ExcursionDTO> excursionsList;
	
    private List<ExcursionDTO> excursionFiltered;
    
    private ExcursionDTO selectedExcursion;
    
	public List<ExcursionDTO> getExcursionFiltered() {
		return excursionFiltered;
	}
	public void setExcursionFiltered(List<ExcursionDTO> excursionFiltered) {
		this.excursionFiltered = excursionFiltered;
	}
	

	public List<ExcursionDTO> getExcursionsList() {
		return excursionsList;
	}
	public void setExcursionsList(List<ExcursionDTO> excursionsList) {
		this.excursionsList = excursionsList;
	}
	
	
	public ExcursionDTO getSelectedExcursion() {
		return selectedExcursion;
	}
	public void setSelectedExcursion(ExcursionDTO selectedExcursion) {
		this.selectedExcursion = selectedExcursion;
	}
	
	@PostConstruct
	public void getAllExcursions(){
		excursionsList=new ArrayList<ExcursionDTO>();
		excursionsList=basicProdMgr.getExcursionsList();
	}
	
	public void purchaseExcursion(){
		selectedExcursion.setIdbuyer(userMgr.getUserDTO().getEmail());
		basicProdMgr.purchase(selectedExcursion);
	}
	
	
}